var crypto = require('crypto');
function McryptService(){

}

//解密 
McryptService.prototype.decode = function(secretdata) {
    var cryptkey = this.cryptKey();
    var iv       = '1234567890000000';
    var decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv),
        decoded  = decipher.update(secretdata, 'base64', 'utf8');

    decoded += decipher.final( 'utf8' );
    return decoded;
}
//解密 
McryptService.prototype.encode = function(cleardata) {
    var cryptkey = this.cryptKey();
    var iv       = '1234567890000000';
    var encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv),
        encoded  = encipher.update(cleardata, 'utf8', 'base64');
    encoded += encipher.final( 'base64' );
    return encoded;
}

McryptService.prototype.cryptKey = function(){
    return crypto.createHash('sha256').update('__tazai_wolf__key').digest();
}


var mcryptService = new McryptService(),

    buf        = 1,
    enc        = mcryptService.encode( buf+"" );

var dec        = mcryptService.decode("qTE0MjzBIUkUWKvu4xb4Q=");


console.warn("Encoded length: ", enc);
console.warn("Decoded all: " + dec);